<% content_with_actions = capture do %>
  <%= polaris_vertical_stack(classes: "Polaris-Banner__ContentWrapper", gap: within_container? ? "1" : "3") do %>
    <% if content.present? || action || secondary_action %>

      <% if content.present? %>
        <%= polaris_box(padding_inline_end: within_container? ? "2" : nil) do %>
          <%= content %>
        <% end %>
      <% end %>

      <% if action || secondary_action %>
        <%= polaris_box do %>
          <%= polaris_button_group do |group| %>
            <% if action %>
              <% group.with_item do %>
                <%= polaris_box(padding_inline_end: "1") do %>
                  <%= action %>
                <% end %>
              <% end %>
            <% end %>

            <% if secondary_action %>
              <% group.with_item do %>
                <%= secondary_action %>
              <% end %>
            <% end %>
          <% end %>
        <% end %>
      <% end %>

    <% end %>
  <% end %>
<% end %>

<%= render Polaris::BaseComponent.new(**system_arguments) do %>
  <% if has_title? && !within_container? %>
    <%= polaris_box(width: "100%") do %>
      <%= polaris_vertical_stack do %>
        <%= polaris_box(classes: "Polaris-Banner__TopBar") do %>
          <%= polaris_horizontal_stack(align: :space_between, block_align: :center, wrap: false, gap: "2") do %>
            <%= polaris_horizontal_stack(wrap: false, gap: "1") do %>
              <% unless @hide_icon %>
                <%= polaris_box do %>
                  <%= render_icon %>
                <% end %>
              <% end %>
              <% if has_title? %>
                <%= polaris_text(as: :h2, variant: :headingSm, break_word: true) do %>
                  <%= @title %>
                <% end %>
              <% end %>
            <% end %>
            <% if dismiss_button %>
              <%= polaris_box(classes: "Polaris-Banner__DismissButton") do %>
                <%= dismiss_button %>
              <% end %>
            <% end %>
          <% end %>
        <% end %>
        <% if has_content? %>
          <%= polaris_box(padding: "4") do %>
            <%= content_with_actions %>
          <% end %>
        <% end %>
      <% end %>
    <% end %>
  <% else %>
    <%= polaris_box(width: "100%", padding: within_container? ? "2" : "3") do %>
      <%= polaris_horizontal_stack(align: :space_between, block_align: :start, wrap: false, gap: "2") do %>
        <%= polaris_horizontal_stack(wrap: false, gap: "1") do %>
          <% unless @hide_icon %>
            <%= polaris_box(classes: "Polaris-Banner__InlineIcon") do %>
              <%= render_icon %>
            <% end %>
          <% end %>
          <%= polaris_box(
            padding: within_container? ? nil : "1",
            padding_block_start: (has_title? || within_container?) ? nil : "1_5",
            classes: has_title? ? nil : "Polaris-Banner__ContainerContentWrapper"
          ) do %>
            <%= polaris_vertical_stack(gap: "1") do %>
              <% if has_title? %>
                <%= polaris_text(as: :h2, variant: :headingSm, break_word: true) do %>
                  <%= @title %>
                <% end %>
              <% end %>
              <% if has_content? %>
                <%= content_with_actions %>
              <% end %>
            <% end %>
          <% end %>
        <% end %>
        <% if dismiss_button %>
          <%= polaris_box(classes: "Polaris-Banner__DismissButton") do %>
            <%= dismiss_button %>
          <% end %>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
<% end %>
